package stack;

import com.alibaba.fastjson.parser.Feature;

import java.util.concurrent.*;

public class IsPalindrome {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        String str = "acbca";
        boolean palindrome = new IsPalindrome().isPalindrome2(str);
        System.out.println(palindrome);

        ExecutorService executorService = Executors.newSingleThreadExecutor();
//        executorService.submit();
//        executorService.execute();

        FutureTask<String> futureTask = new FutureTask<String>(new Callable<String>() {
            @Override
            public String call() throws Exception {
                System.out.println("测试");
                return "success";
            }
        });
        executorService.submit(futureTask);
        String s = futureTask.get();
        System.out.println(s);
    }

    public boolean isPalindrome(String s) {
        StringBuffer sgood = new StringBuffer();
        int len = s.length();
        for (int i = 0; i < len; i++) {
            char ch = s.charAt(i);
            if (Character.isLetterOrDigit(ch)) {
                sgood.append(Character.toLowerCase(ch));
            }
        }
        StringBuffer sgood_rev = new StringBuffer(sgood).reverse();
        return sgood.toString().equals(sgood_rev.toString());
    }


    public boolean isPalindrome2(String s) {
        StringBuffer sgood = new StringBuffer();
        int len = s.length();
        for (int i = 0; i < len; i++) {
            char ch = s.charAt(i);
            if (Character.isLetterOrDigit(ch)) {
                sgood.append(Character.toLowerCase(ch));
            }
        }
        int n = sgood.length();
        int left = 0;
        int right = n - 1;
        while (left < right) {
            if (sgood.charAt(left) != sgood.charAt(right)) {
                return false;
            }
            ++left;
            --right;
        }
        return true;
    }


}
